package temp.lho.lws.controller;

import org.springframework.web.bind.annotation.*;
import temp.lho.lws.pojo.FyInfo;
import temp.lho.lws.pojo.WarrantyInfo;
import temp.lho.lws.service.IWarrantyInfoService;
import temp.lho.lws.vo.LayuiResult;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * (WarrantyInfo)表控制层
 *
 * @author makejava
 * @since 2020-07-06 23:08:54
 */
@RestController
@RequestMapping("warrantyInfo")
public class WarrantyInfoController {

    Date date = new Date();
    SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");

    /**
     * 服务对象
     */
    @Resource
    private IWarrantyInfoService warrantyInfoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public WarrantyInfo selectOne(Integer id) {
        return this.warrantyInfoService.queryById();
    }


    /**
     * 删除
     * @param warranty
     * @return
     */
    @RequestMapping("/delewarr")
    @ResponseBody
    public Integer delewarr(WarrantyInfo warranty){
        System.out.println("---------------->"+warranty);
        return warrantyInfoService.deleteById(warranty);
    }

    /**
     * 修改
     */
    @RequestMapping("/updwarr")
    public Integer updwarr(@RequestBody WarrantyInfo aaa){
        System.out.println("---------------->"+aaa);
        Integer a = warrantyInfoService.updWarr(aaa);
        System.out.println("---------------->"+a);
        return a;
    }


    /*增加*/
    @RequestMapping("/addWarrantyInfo")
    //@ResponseBody
    public int addwarr(WarrantyInfo aaa) throws Exception{

        Date dd = new SimpleDateFormat("yyyy-MM-dd").parse(aaa.getInsuranceendtime());
        Date ddd = new SimpleDateFormat("yyyy-MM-dd").parse(aaa.getInsuranceEndTime2());
        Date dddd = new SimpleDateFormat("yyyy-MM-dd").parse(dateFormat.format(date));
        if(dd.compareTo(dddd) >= 0){
            aaa.setWarrantystate(1);
        }else if(dd.compareTo(dddd) < 0){
            aaa.setWarrantystate(2);
        }
        System.out.println(">>>>>>>>>>>>>>>>>>>>.."+aaa);

        int a = warrantyInfoService.addWarr(aaa);
        if(aaa.getSex1() != "" && aaa.getSex1() != null){
            if(ddd.compareTo(dddd) >= 0){
                aaa.setWarrantystate(1);
            }else if(ddd.compareTo(dddd) < 0){
                aaa.setWarrantystate(2);
            }
            System.out.println("aaaaaa啊啊啊啊啊啊啊啊啊啊啊啊啊");
            warrantyInfoService.addWarr2(aaa);
        }
        return 0;
    }

    /*条件查询*/
    @RequestMapping("/selewa")
    public FyInfo selewa(FyInfo f){

        return null;
    }

    /**
     *
     */

    /**
     * 显示
     * @return
     */
    @RequestMapping("/seleAll")
    @ResponseBody
    public LayuiResult seleAll(WarrantyInfo warranty){
        System.out.println("-----------------"+warranty);
        List<WarrantyInfo> wa = warrantyInfoService.seleAll(warranty);
        Integer pagenum = warrantyInfoService.getPage();
        LayuiResult layuiResult = new LayuiResult(0,"",pagenum,wa);
        return layuiResult;
    }

}